<template>
    <div>
        房型名称： <input type="text" style="width: 80px;" v-model="name">
    

        <input type="button" value="查询" @click="pdxs">

        <input type="button"  value="导出" @click="exporFile">


<table class="table table-bordered" border="1">
   <thead>
    <tr style="background-color: aqua;">
        <td>房型名称</td>
        <td>门市价</td>
        <td>押金</td>
        <td>面积</td>
        <td>可住人数</td>
        <td>是否加床</td>
        <td>房型介绍</td>
        <td>房型投放</td>
        <td>交通信息</td>
        <td>是否删除</td>
        <td>删除时间</td>
        <td>操作</td>
    </tr>
   </thead>

   <tbody>
    <tr v-for="item in xs">
        <td>{{item.rType_name}}</td>
        <td>{{item.rType_price}}</td>
        <td>{{item.rType_deposit}}</td>
        <td>{{item.rType_size}}</td>
        <td>{{item.rType_num==1?"是":"否"}}</td>
        <td>{{item.rType_Addbed}}</td>
        <td><img :src="item.rType_img" style="width: 40px; height: 40px;"></td>
        <td>{{item.rType_info}}</td>
        <td>{{item.rType_state}}</td>
        <td>{{item.RType_infd}}</td>
        <td>{{item.datet}}</td>
        
        <td><a href="#" style="margin-right: 10px;" @click="sc(item.rType_id)">删除</a>
            <a href="#" style="margin-right: 10px;" @click="xg(item.rType_id)">修改</a></td>
    </tr>
   </tbody>
</table>

当前第{{fy.pageindex}}页,共{{fy.ys}}页，共{{ fy. conut}}行
<a href="#" style="margin-right: 10px;" @click="fyxs('a')">首页</a>
<a href="#" style="margin-right: 10px;" @click="fyxs('b')">上一页</a>
<a href="#" style="margin-right: 10px;" @click="fyxs('c')">下一页</a>
<a href="#" style="margin-right: 10px;" @click="fyxs('d')">尾页</a>

<select v-model="said" @change="asjdad">
    <option :value="1">每页1条</option>
    <option :value="2">每页2条</option>
    <option :value="3">每页3条</option>
</select>


<input type="text" v-model="asjo">
<input type="button" value="跳转" @click="jio">

    </div>
</template>

<script setup lang="ts">
import {  ref,onMounted} from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
const asjo=ref("");
const said=ref(1);
const Router=useRouter();
const name=ref("");


const xs=ref([{

    rType_id: 0,
  rType_name: "",
  rType_price: 0,
  rType_deposit: 0,
  rType_size: 0,
  rType_num: 0,
  rType_Addbed: "",
  rType_img: "",
  rType_info: "",
  rType_state: "",
  RType_infd: false,
  datet: ""

}])


onMounted(()=>{

    asjdad();
    pdxs();
 
})



const fy=ref({

pageindex:1,
pageszie:2,
conut:0,
ys:0



})



const pdxs=()=>{
axios.get('https://localhost:7268/api/fx/fxshow',{

params:{

    rType_name:name.value,
    pageindex:fy.value.pageindex,
    pageszie:fy.value.pageszie
}

})
.then(res=>{
console.log(res.data)
    xs.value=res.data.pagedate
    fy.value.conut=res.data.pagecount
    fy.value.ys=res.data.totalcount
    
})
.catch(error=>{

console.log(error)

})

}


const fyxs=(fyid:string)=>{

switch (fyid) {
    case "a":
    fy.value.pageindex=1;
 
        break;

   
        case "b":
  if(fy.value.pageindex>1)
  {

    fy.value.pageindex--
   
  }
  else{

    alert('当前已经是第一页')
  }

        break;




        case "c":
  if(fy.value.pageindex<fy.value.ys)
  {

    fy.value.pageindex++
   
  }
  else{

    alert('当前已经是最后一页');
  }

        break;



        case "d":
        fy.value.pageindex=fy.value.ys
 

        break;

}

pdxs();


}

const sc=(scid:number)=>{
axios.delete('https://localhost:7268/api/fx/sclist',{

    params:{

        rType_id:scid
    }


})
.then(res=>{

if(res.data>0)
{
xs.value.datet=res.data
    alert('删除成功');
 

pdxs();
}
else{

    alert('删除失败');
}

})
.catch(error=>{

    console.log(error)
})
}





const xg=(xgid:number)=>{

    Router.push({

name:"fxxg",
params:{

id:xgid
}



    })

}




const asjdad=()=>{

    fy.value.pageszie=said.value;
    pdxs();

}



const jio=()=>{

fy.value.pageindex=Number(asjo.value) 
pdxs();

}

const exporFile=()=>{
axios.post('https://localhost:7268/api/fx/EXporRoomtypeinfo?Pathname='+"C:\\导入导出\\asdasd.xlsx"
)
.then(res=>{

if(res.data>0)
{
alert('导出成功')

}

})
.catch(error=>{

    console.log(error)
})

}

</script>

<style scoped>

</style>